package com.example.zyfypt525lmj.Activity.zyfypt525lmj.Activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

import cst.czh.a923.zyfypt_923czh.Listener.AmicoolListener;
import cst.czh.a923.zyfypt_923czh.R;
import cst.czh.a923.zyfypt_923czh.ResModel;

/**
 * Created by apple on 2017/5/17.
 */

public class RegActivity extends AppCompatActivity {
    private EditText username;
    private EditText password;
    private EditText tel;
    private EditText email;
    private EditText realname;
    private EditText roleid;
    private Button reg;
    private RadioButton student;
    private RadioButton teacher;
    private ResModel model;
    private AmicoolListener<String> listener;
   String jiekou=null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_reg);
        username = (EditText) findViewById(R.id.reg_uername);
        password = (EditText) findViewById(R.id.reg_password);
        tel = (EditText) findViewById(R.id.reg_tel);
        roleid=(EditText) findViewById(R.id.reg_roleid);
        email = (EditText) findViewById(R.id.reg_email);
        realname=(EditText) findViewById(R.id.reg_realname);
        student = (RadioButton) findViewById(R.id.reg_student);
        teacher = (RadioButton) findViewById(R.id.reg_teacher);
        reg = (Button) findViewById(R.id.btn_reg2);
        listener=new AmicoolListener<String>()
        {
            @Override
            public void onResponse(String l) {
                if(realname.length()==0||email.length()==0||username.length()==0||password.length()==0||tel.length()==0)
                    if(l.equals("1")){
                        Toast.makeText(RegActivity.this, "注册成功", Toast.LENGTH_SHORT).show();

                    }
                    else{
                        Toast.makeText(RegActivity.this,"注册失败",Toast.LENGTH_SHORT).show();

                    }

            }

            @Override
            public void onFail(String msg) {
                Toast.makeText(RegActivity.this,msg,Toast.LENGTH_SHORT).show();

            }
        };
       student.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               jiekou="2";
            }
        });
       teacher.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                jiekou="3";
            }
        });
        reg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                model = new ResModel("s");
                model.reg(username.getText().toString(),password.getText().toString(),tel.getText().toString(),jiekou,realname.getText().toString(),email.getText().toString(),listener);

            }
        });



    }

}
